package com.leetcode.demo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: WuPeng
 * @Date: 2021/7/7 5:09 下午
 */
public class FirstMissNum {

    public int firstMissingPositive(int[] nums) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > 0){
                map.put(nums[i], 1);
            }
        }
        for (int i = 1; i <= nums.length; i++) {
            if (!map.containsKey(i)) return i;
        }
        return nums.length+1;
    }

    public static void main(String[] args) {
        int[] nums = {7,8,9,11,12};
        FirstMissNum firstMissNum = new FirstMissNum();
        int target = firstMissNum.firstMissingPositive(nums);
        System.out.println(target);
    }

}
